/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UpAnh;

import Entity.DAL;
import java.net.ServerSocket;
import java.net.Socket;

/**
 *
 * @author Mr Bao
 */
public class Server implements Runnable {

    private ServerSocket serverSocket;
    private DAL d;

    public Server() {
        try {
            serverSocket = new ServerSocket(1234);
            d = new DAL();
            new Thread(this).start();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public void run() {
        while (true) {
            try {
                Socket socket = serverSocket.accept();
                System.out.println(socket.getInetAddress() + " connect");
                Client client = new Client(socket, d);
                Thread.sleep(200);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            System.gc();
        }
    }
}
